import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/pages/home/news/news_detail_controller.dart';
import 'package:flutter_changdian_football/widget/default_page/custom_empty.dart';
import 'package:flutter_changdian_football/widget/load_state/load_state_layout.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:get/get.dart';

// 新闻详情
class NewsDetailPage extends StatelessWidget {
  const NewsDetailPage({super.key, required this.newsId});

  final String newsId;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        backgroundColor: const Color(0xffF8FAF9),
        elevation: 0,
        title: Text(
          '详情',
          style: TextStyle(fontSize: 16.sp, color: const Color(0xff333333)),
        ),
        iconTheme: const IconThemeData(
          color: Color(0xff333333)
        ),
      ),
      body: GetBuilder<NewsDetailController>(
        init: NewsDetailController(newsId: newsId),
        builder: (newsDetailController) {
          return LoadStateLayout(
            state: newsDetailController.state,
            empty: const Center(
              child: CustomEmpty(
                text: '暂无此消息信息',
              ),
            ),
            success: SingleChildScrollView(
              physics: const BouncingScrollPhysics(),
              padding: EdgeInsets.symmetric(horizontal: 15.w, vertical: 10.w),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  SizedBox(
                    child: Text(
                      newsDetailController.newsDetailModel?.title ?? '', 
                      style: TextStyle(
                        fontSize: 16.sp, 
                        height: 1.5, 
                        fontWeight: FontWeight.w500, 
                        color: const Color(0xff3D3D3D)
                      )
                    ),
                  ),
          
                  SizedBox(height: 12.w,),
          
                  SizedBox(
                    child: Text(
                      newsDetailController.newsDetailModel?.publishDatetime ?? '', 
                      style: TextStyle(
                        fontSize: 12.sp, 
                        color: const Color(0xff888888)
                      )
                    ),
                  ),
          
                  SizedBox(height: 16.w),
                  SizedBox(
                    child: HtmlWidget(
                      newsDetailController.newsDetailModel?.newsContent ?? '',
                      onErrorBuilder: (context, element, error) => Text('$element error: $error'),
                      onLoadingBuilder: (context, element, loadingProgress) => Center(
                        child: CircularProgressIndicator(
                          color: const Color(0xff499360),
                          strokeWidth: 4.w,
                        ),
                      ),
                      renderMode: RenderMode.column,
                      textStyle: TextStyle(fontSize: 14.sp, color: const Color(0xff444444), height: 1.5),
                    ),
                  ),
                ],
              ),
            ),
          );
        }
      ),
    );
  }
}